package com.itheima.edu.info.manager.service.impl;

import com.itheima.edu.info.manager.domain.Teacher;
import com.itheima.edu.info.manager.service.TeacherService;

public class TeacherServiceImpl implements TeacherService {


    @Override
    public boolean addTeacher(Teacher teacher) {
        boolean flag = teacherDao.addTeacher(teacher);
        return flag;
    }

    @Override
    public boolean isExists(String id) {
        System.out.println(id);
        Teacher[] teachers = teacherDao.findAllTeacher();
        for (int i = 0; i < teachers.length; i++) {
            if (teachers[i] != null && teachers[i].getId().equals(id)){
                return true;
            }
        }
        return false;
    }

    @Override
    public boolean delectTeacherById(String id) {
        boolean flag = teacherDao.delectTeacher(id);
        return flag;
    }

    @Override
    public Teacher selectTeacher(String id) {
        Teacher teacher = teacherDao.selectTeacher(id);
        return teacher;
    }

    @Override
    public Teacher updataTeacher(Teacher teacher) {
        Teacher tea = teacherDao.updataTeacher(teacher);
        return tea;
    }

    @Override
    public Teacher[] findAllTeacher() {
        Teacher[] allTeacher = teacherDao.findAllTeacher();
        for (int i = 0; i < allTeacher.length; i++) {
            if (allTeacher[i] != null){
                return allTeacher;
            }
        }
        return null;
    }
}
